package com.melon.web.exception;

import com.google.gson.JsonObject;
import com.melon.utils.GSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 处理Spring Controller中 抛出的 Excption
 */
@Slf4j
@Component
public class ResponseExceptionHandler implements HandlerExceptionResolver {

    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        if (e instanceof RuntimeException) {
            e.printStackTrace();
            ModelAndView model = new ModelAndView();
            model.setViewName("/test");
            return model;
        }
        return null;
    }
}
